﻿using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
using Quick.EntityFrameworkCore.Design;

namespace SampleModels;

public class DesignTimeFactory : AutoDesignTimeDbContextFactoryBase<DataDbContext>
{
    protected override void ConfigureServices(HostBuilderContext hostContext, IServiceCollection services)
    {
        base.ConfigureServices(hostContext, services);

        AutoConfiguration.Configure(services);
    }

    protected override void ConfigureDatabaseOptions(HostBuilderContext hostContext, IServiceCollection services)
    {
        base.ConfigureDatabaseOptions(hostContext, services);

        services.AddDatabaseProviderOptions<NpgsqlDbContextOptionsBuilder>(options =>
        {
            options.MigrationsAssembly(MigrationsAssemblyName);
            options.MigrationsHistoryTable(MigrationsHistoryTableName);
        });

        services.AddDatabaseProviderOptions<SqliteDbContextOptionsBuilder>(options =>
        {
            options.MigrationsAssembly(MigrationsAssemblyName);
            options.MigrationsHistoryTable(MigrationsHistoryTableName);
        });
    }
}
